const { ccclass, property } = cc._decorator;
import MyEnums from '../MyEnums';

@ccclass
export default class StatusNodeControl extends cc.Component {
    @property()
    reinforce: number = 0.2;//强化系数
    @property()
    impair: number = -0.1;//虚弱系数
    @property(cc.NodePool)
    nodePools: cc.NodePool[] = [];
    @property([cc.Prefab])
    prefabNodes: cc.Prefab[] = [];
    @property
    StatusTypeCount: number = 7;
    //获取属性增益系数
    getCoffe(attribute: number, AttributeList: boolean[]): number {
        let coefficient = 1;
        switch (attribute) {
            case MyEnums.SkillAttribute.Fire://克水，生风
                {
                    if (AttributeList[MyEnums.SkillAttribute.Water]) {
                        return 0;
                    }
                    if (AttributeList[MyEnums.SkillAttribute.Wind]) {
                        coefficient += this.reinforce;
                    }
                    break;
                }
            case MyEnums.SkillAttribute.Water://克火，弱毒
                {
                    if (AttributeList[MyEnums.SkillAttribute.Fire]) {
                        return 0;
                    }
                    if (AttributeList[MyEnums.SkillAttribute.Poison]) {
                        coefficient += this.impair;
                    }
                    break;
                }
            case MyEnums.SkillAttribute.Wind://风助火
                {
                    if (AttributeList[MyEnums.SkillAttribute.Fire]) {
                        coefficient += this.reinforce;
                    }
                    break;
                }
        }
        return coefficient;
    }
    //初始化状态节点
    initNodes(StatusPrefabs: Map<string, cc.Prefab>) {
        for (let i = 0; i < this.StatusTypeCount; i++) {
            let key = MyEnums.SkillStatusType[i];
            let pfb = StatusPrefabs.get(key);
            if (pfb) {
                this.prefabNodes[i] = pfb;
            }
            else {
                this.prefabNodes[i] = null;
            }
        }
    }
    //获取状态结点
    getNodePool(StatusType: number) {
        let node = this.nodePools[StatusType];
        if (node?.size() > 0) {
            return node.get();
        }
        else {
            if (this.prefabNodes[StatusType])
                return cc.instantiate(this.prefabNodes[StatusType]);
            return null;
        }
    }
    //回收缓存
    setNodePool(StatusType: number, node: cc.Node) {
        let nodePool = this.nodePools[StatusType];
        if (nodePool) {
            nodePool.put(node);
        }
        else {
            nodePool = new cc.NodePool();
            nodePool.put(node);
            this.nodePools[StatusType] = nodePool;
        }
    }
}
